<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>es6array新方法</title>
</head>

<body>
    <script>
        //map
        // if (item >= 60) {
        // return "及格";
        // } else {
        // return "不及格";
        // }
        console.log("---------map方法-----------")
        let mps = [68, 53, 12, 98, 65];
        let mps2 = mps.map((item) => item >= 60 ? "及格" : "不及格");
        //原数组
        console.log(...mps)
        //map处理后的数组
        console.log(...mps2)

        console.log("---------reduce方法-----------")
        //reduce
        let reduces = [68, 53, 12, 98, 65];
        let result = reduces.reduce((tmp, item, index) => {
            console.log("index:" + index + "tmp:" + tmp + "item" + item)
            if (index == reduces.length - 1) {
                return (tmp + item) / reduces.length
            } else {
                return tmp + item
            }
        });
        //求和
        //alert(result)
        //filter ,案例: 求偶数
        console.log("---------filter方法-----------")
        let filters = [68, 53, 12, 98, 65];
        let resfilters = filters.filter((item)=>{
            //能被2整除说明就是偶数,然后返回出来
            return item % 2 == 0;
        })
        console.log(resfilters)
        console.log("---------ForEach方法-----------")
        let arrs = [68, 53, 12, 98, 65];
        arrs.forEach((item,index) => {
            console.log("item: " + item + " " + "index: " + index)
        });
    </script>
</body>
<!-- 

原生array扩展

map       映射,一一对应    获取到相应值按照自己的处理再返回出来    参数:item,index
reduce    求平均值   进去n个出来n个                             参数:tmp,item,index
filter    过滤,过滤出你想要的值   进去n个出来的为过滤值           参数:item,index
forEach   参数:item.index      遍历数组
 -->

</html>